package com.rs;

import java.io.IOException;

import com.rs.cache.Cache;
import com.rs.cache.loaders.ItemsEquipIds;
import com.rs.cores.CoresManager;
import com.rs.game.World;
import com.rs.game.map.MapBuilder;
import com.rs.game.npc.combat.CombatScriptsHandler;
import com.rs.game.player.LendingManager;
import com.rs.game.player.content.FishingSpotsHandler;
import com.rs.game.player.content.ForumRights;
import com.rs.game.player.content.FriendChatsManager;
import com.rs.game.player.content.clans.ClansManager;
import com.rs.game.player.content.grandExchange.GrandExchange;
import com.rs.game.player.controlers.ControlerHandler;
import com.rs.game.player.cutscenes.CutscenesHandler;
import com.rs.game.player.dialogues.DialogueHandler;
import com.rs.game.world.area.AreaManager;
import com.rs.net.decoders.handlers.BackUpHandler;
import com.rs.utils.Censor;
import com.rs.utils.DTRank;
import com.rs.utils.DisplayNames;
import com.rs.utils.IPBanL;
import com.rs.utils.IPMuteL;
import com.rs.utils.ItemBonuses;
import com.rs.utils.ItemDestroys;
import com.rs.utils.ItemExamines;
import com.rs.utils.ItemSpawns;
import com.rs.utils.Logger;
import com.rs.utils.MapArchiveKeys;
import com.rs.utils.MapAreas;
import com.rs.utils.MusicHints;
import com.rs.utils.NPCBonuses;
import com.rs.utils.NPCCombatDefinitionsL;
import com.rs.utils.NPCDrops;
import com.rs.utils.NPCExamines;
import com.rs.utils.NPCSpawning;
import com.rs.utils.NPCSpawns;
import com.rs.utils.ObjectSpawns;
import com.rs.utils.PkRank;
import com.rs.utils.SQL;
import com.rs.utils.ShopsHandler;
import com.rs.utils.Utils;
import com.rs.utils.huffman.Huffman;
import com.runetoplist.RuneTopList;

//1166 interface for start. 
public class Initializer {
		
	public static void loadNPCData() throws IOException {
		try {
			Logger.log("Initializer", "Retrieving NPC Data.");
			CombatScriptsHandler.init();
			NPCSpawns.init();
			NPCCombatDefinitionsL.init();
			NPCBonuses.init();
			NPCDrops.init();
			NPCExamines.init();
			NPCSpawning.spawnNPCS();
			NPCSpawning.npcSpawn();
		} catch (Throwable e) {
			Logger.handle(e);
			Logger.log("Initializer", "Failed in Retrieving All NPC Data!");
		}
		Logger.log("Initializer", "Succesfully Retrieved All NPC Data!");
	}
	
	public static void loadCacheData() throws IOException {
		try {
			Logger.log("Initializer", "Retrieving Cache Data.");
			Cache.init();
			Huffman.init();
			ItemsEquipIds.init();
			CoresManager.init();
		} catch (Throwable e) {
			Logger.handle(e);
			Logger.log("Initializer", "Failed in Retrieving All Cache Data!");
		}
		Logger.log("Initializer", "Succesfully Retrieved All Cache Data!");
	}
	
	public static void loadMySQLData() throws IOException {
		try {
			Logger.log("Initializer", "Retrieving MySQL Data.");
			SQL.createConnection();
			ForumRights.createConnection();
			Logger.log("Launcher", "Retrieving RuneTopList Voting Script");
			RuneTopList.init("Styx", "lgrulm2mtxtg9zfr");
		} catch (Throwable e) {
			Logger.handle(e);
			Logger.log("Initializer", "Failed in Retrieving All MySQL Data!");
		}
		Logger.log("Initializer", "Succesfully Retrieved All MySQL Data!");
	}
	
	public static void loadMapData() throws IOException {
		try {
			Logger.log("Initializer", "Retrieving Map Data.");
			MapArchiveKeys.init();
			MapAreas.init();
			MapBuilder.init();
			} catch (Throwable e) {
			Logger.handle(e);
			Logger.log("Initializer", "Failed in Retrieving All Map Data!");
		}
		Logger.log("Initializer", "Succesfully Retrieved All Map Data!");
	}
	
	public static void loadItemData() throws IOException {
		try {
			Logger.log("Initializer", "Retrieving Item Data.");
			ItemDestroys.init();
			ItemSpawns.init();
			ItemExamines.init();
			ItemBonuses.init();
			} catch (Throwable e) {
			Logger.handle(e);
			Logger.log("Initializer", "Failed in Retrieving All Item Data!");
		}
		Logger.log("Initializer", "Succesfully Retrieved All Item Data!");
	}
	
	public static void loadObjectData() throws IOException {
		try {
			Logger.log("Initializer", "Retrieving Object Data.");
			ObjectSpawns.init();
			} catch (Throwable e) {
			Logger.handle(e);
			Logger.log("Initializer", "Failed in Retrieving All Object Data!");
		}
		Logger.log("Initializer", "Succesfully Retrieved All Object Data!");
	}
	
	public static void loadWorldData() throws IOException {
		try {
			Logger.log("Initializer", "Retrieving World Data.");
			World.init();
			} catch (Throwable e) {
			Logger.handle(e);
			Logger.log("Initializer", "Failed in Retrieving All World Data!");
		}
		Logger.log("Initializer", "Succesfully Retrieved All World Data!");
	}
	
	public static void loadSerData() throws IOException {
		try {
			Logger.log("Initializer", "Retrieving Ser. Data.");
			Censor.init();
			DisplayNames.init();
			IPMuteL.init();
			IPBanL.init();
			PkRank.init();
			DTRank.init();
			MusicHints.init();
			} catch (Throwable e) {
			Logger.handle(e);
			Logger.log("Initializer", "Failed in Retrieving All Ser. Data!");
		}
		Logger.log("Initializer", "Succesfully Retrieved All Ser. Data!");
	}
	
	public static void loadHandlersData() throws IOException {
		try {
			Logger.log("Initializer", "Retrieving Handlers Data.");
			ShopsHandler.init();
			FishingSpotsHandler.init();
			DialogueHandler.init();
			ControlerHandler.init();
			CutscenesHandler.init();
			} catch (Throwable e) {
			Logger.handle(e);
			Logger.log("Initializer", "Failed in Retrieving All Handlers Data!");
		}
		Logger.log("Initializer", "Succesfully Retrieved All Handlers Data!");
	}
	
	public static void loadManagersData() throws IOException {
		try {
			Logger.log("Initializer", "Retrieving Managers Data.");
			GrandExchange.init();
			LendingManager.init();
			FriendChatsManager.init();
			ClansManager.init();
			} catch (Throwable e) {
			Logger.handle(e);
			Logger.log("Initializer", "Failed in Retrieving All Managers Data!");
		}
		Logger.log("Initializer", "Succesfully Retrieved All Managers Data!");
	}
	
	public static void loadFiles() throws IOException {
		loadCacheData();
		loadSerData();
		loadMapData();
		loadHandlersData();
		loadManagersData();
		loadWorldData();
		loadObjectData();
		loadItemData();
		loadNPCData();
		if (Utils.isDev())
			return;
		else {
		loadMySQLData();
		}
		BackUpHandler.go();
		AreaManager.init();
	}
}